package view 
{
	import salomon.event.TextureManagerEvent;
	import salomon.manager.TextureManager;
	import starling.display.Sprite;
	import starling.events.Event;
	import starling.events.Touch;
	import starling.events.TouchEvent;
	import starling.events.TouchPhase;

	/**
	 * ...
	 * @author Tiago Salomon
	 */
	public class GameView extends Sprite 
	{

		private var _soldier		:SoldierView;
		private var _background		:BackgroundView;
		private var _textureManager	:TextureManager;
		
		public function GameView() 
		{
			this.addEventListener(Event.ADDED_TO_STAGE, initialize);
		}
		
		private function initialize(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, initialize);
			
			//this.addEventListener(TouchEvent.TOUCH, onTouch);
			
			_textureManager = new TextureManager();
			_textureManager.addEventListener(TextureManagerEvent.COMPLETE, onTexturesReady);
			
			_textureManager.addItem("Hero", "xml/Soldier.xml", "img/hero/Soldier.png");
			_textureManager.addItem("Background", "xml/Ambient.xml", "img/ambient/Ambient.png");			
			
			_textureManager.initialize();

		}		
		
		private function onTexturesReady(e:TextureManagerEvent):void 
		{
			_background = new BackgroundView(_textureManager);
			this.addChild(_background);
			
			_soldier = new SoldierView(_textureManager);
			this.addChild(_soldier);
			
		}
		/*
		private function onTouch(event:TouchEvent):void 
		{
            var touches:Vector.<Touch> = event.getTouches(this);
            
            for each (var touch:Touch in touches)
            {
				if (touch.phase == TouchPhase.ENDED)
				{					
					getPosition(touch);
				}
			}
		}
		
		private function getPosition(touch:Touch):void 
		{
			//_soldier.walkTo(touch.globalX, touch.globalY);
		}
		*/
	}

}